import { deleteByPrimaryKeyForProUserGroup, selectByPrimaryKeyForProUserGroup, insertForProUserGroup, updateForProUserGroup, deleteByMapForProUserGroup,updateByMapForProUserGroup, getOneForProUserGroup,getAllForProUserGroup,queryPageForProUserGroup, countForProUserGroup, insertBatchForProUserGroup, deleteBatchForProUserGroup,updateBatchForProUserGroup ,queryPageForProGroup,getPageProUserByGroupId,queryPageForProUserChild,getSelectedProUserByGroupId } from '@/services/system/api_prousergroup';

export default {
    namespace: 'prousergroup',

    state: {
        data: {
            list: [],
            pagination: {},
        },
        group: {
        	list: [],
            pagination: {},
        },
        userChild: {
        	list: [],
            pagination: {},
        },
        userSelect: {
        	list: [],
        },
    },

    effects: {
            *delete_by_primarykey_for_prousergroup({ payload }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForProUserGroup, payload);
                yield put({
                    type: 'deleteByPrimaryKeyForProUserGroup',
                    payload: response,
                });
            },
            *select_by_primarykey_for_prousergroup({ payload, callback }, { call, put }) {
                const response = yield call(selectByPrimaryKeyForProUserGroup, payload);
                yield put({
                    type: 'selectByPrimaryKeyForProUserGroup',
                    payload: response,
                });
                if (callback) callback();
            },
            *insert_for_prousergroup({ payload, callback }, { call, put }) {
                const response = yield call(insertForProUserGroup, payload);
                yield put({
                    type: 'insertForProUserGroup',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_for_prousergroup({ payload, callback }, { call, put }) {
                const response = yield call(updateForProUserGroup, payload);
                yield put({
                    type: 'updateForProUserGroup',
                    payload: response,
                });
                if (callback) callback();
            },
            *delete_by_map_for_prousergroup({ payload, callback }, { call, put }) {
                const response = yield call(deleteByMapForProUserGroup, payload);
                yield put({
                    type: 'deleteByMapForProUserGroup',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_by_map_for_prousergroup({ payload, callback }, { call, put }) {
                const response = yield call(updateByMapForProUserGroup, payload);
                yield put({
                    type: 'updateByMapForProUserGroup',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_one_for_prousergroup({ payload, callback }, { call, put }) {
                const response = yield call(getOneForProUserGroup, payload);
                yield put({
                    type: 'getOneForProUserGroup',
                    payload: response,
                });
                if (callback) callback();
            },
            *query_page_for_prousergroup({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProUserGroup, payload);
                yield put({
                    type: 'queryPageForProUserGroup',
                    payload: response,
                });
                if (callback) callback();
            },
            *count_for_prousergroup({ payload, callback }, { call, put }) {
                const response = yield call(countForProUserGroup, payload);
                yield put({
                    type: 'countForProUserGroup',
                    payload: response,
                });
                if (callback) callback();
            },
            *insert_batch_for_prousergroup({ payload, callback }, { call, put }) {
                const response = yield call(insertBatchForProUserGroup, payload);
                yield put({
                    type: 'insertBatchForProUserGroup',
                    payload: response,
                });
                
                const responsedata = yield call(queryPageForProGroup, {});
                yield put({
                	type: 'queryPageForProGroup',
                	payload: responsedata,
                });
                
                const newPayload = { group_id: [payload.groupids[0].id]};
                const responseUser = yield call(getPageProUserByGroupId, newPayload);
                yield put({
                    type: 'getPageProUserByGroupId',
                    payload: responseUser,
                });
                
                if (callback) callback();
            },
            *delete_batch_for_prousergroup({ payload, callback }, { call, put }) {
                const response = yield call(deleteBatchForProUserGroup, payload);
                yield put({
                    type: 'deleteBatchForProUserGroup',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_batch_for_prousergroup({ payload, callback }, { call, put }) {
                const response = yield call(updateBatchForProUserGroup, payload);
                yield put({
                    type: 'updateBatchForProUserGroup',
                    payload: response,
                });
                if (callback) callback();
            },
            *query_page_for_progroup({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProGroup, payload);
                yield put({
                    type: 'queryPageForProGroup',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_page_for_user_by_groupid({ payload, callback }, { call, put }) {
                const response = yield call(getPageProUserByGroupId, payload);
                yield put({
                    type: 'getPageProUserByGroupId',
                    payload: response,
                });
                if (callback) callback();
            },
            *query_page_for_prouserchild({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProUserChild, payload);
                yield put({
                    type: 'queryPageForProUserChild',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_selected_prouser_by_groupid({ payload, callback }, { call, put }) {
                const response = yield call(getSelectedProUserByGroupId, payload);
                yield put({
                    type: 'getSelectedProUserByGroupId',
                    payload: response,
                });
                if (callback) callback();
            },
            },

    reducers: {
        deleteByPrimaryKeyForProUserGroup(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        selectByPrimaryKeyForProUserGroup(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertForProUserGroup(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateForProUserGroup(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByMapForProUserGroup(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateByMapForProUserGroup(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getOneForProUserGroup(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProUserGroup(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        countForProUserGroup(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertBatchForProUserGroup(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteBatchForProUserGroup(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateBatchForProUserGroup(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getPageProUserByGroupId(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProGroup(state, action) {
            return {
                ...state,
                group: action.payload,
            };
        },
        queryPageForProUserChild(state, action) {
            return {
                ...state,
                userChild: action.payload,
            };
        },
        getSelectedProUserByGroupId(state, action) {
            return {
                ...state,
                userSelect: action.payload,
            };
        },
    },
};
